package binarysearchnorecursion;

public class BinarySearchNoRecur {
    public int binarySeacr(int[] arr, int target) {
        int left = 0;
        int right = arr.length - 1;
        while (left <= right) {
            int mid = (right + left) >> 1;
            if (arr[mid] == target) {
                return mid;
            } else if (arr[mid] > target) {
                right= mid - 1;
            } else {
                left= mid + 1;
            }
        }
        return -1;
    }
}
